namespace Demo.DbContext;

public class UserRepository
{
    public int Add(User user)
    {
        DbContext.DbContexts.users.Add(user);
        return 1;
    }
    public int Update(User user)
    {
        // 选出与传入用户ID相同的用户
        var target = DbContexts.users.Single(x => x.Id == user.Id);

        // 将新值赋给目标用户
        target.Age = user.Age;
        target.Gender = user.Gender;
        target.Name = user.Name;
        return 1;
    }
    public int Remove(User user)
    {
        var target = DbContexts.users.Single();
        return 1;
    }
    public User? GetByID(int id)
    {
        return DbContexts.users.SingleOrDefault(x => x.Id == id);
    }
    public User? GetByEmail(string email)
    {
        return DbContexts.users.SingleOrDefault(x => x.Email.Equals(email, StringComparison.OrdinalIgnoreCase));
    }
    public List<User> Exproler()
    {
        return DbContexts.users;
    }
}
